$import("com.joypard.platform.shortcut.ShortCutDI");
/**
 * 用户
 */
K.defView("com.joypard.platform.shortcut.ShortCutView", {
	ctrl : null,
	purviewConfig : {
		view : "platform.shortcut"
	},
	initialize : function() {
		E.addListener("快捷-保存-成功", function() {
			K.m("设置成功").show(this.centerPanel.tbar);
		}, this);
	},
	render : function() {
		var me = this;
		this.centerPanel = this.createCenterPanel();
		this.userResTree = this.createUFGResTree();

		this.userResTree.on("afterrender", function() {
			var root = this.getRootNode();
			if (root.childNodes.length) {
				root.childNodes[0].select();
			}
		}, this.userResTree);

		this.userResTree.getSelectionModel().on("selectionchange", function(model, node) {
			me.centerPanel.load({
				method : "GET",
				url : ShortCutDI.urls.updateShortCut,
				params : {
					parentResId : node.id
				}
			});
		});

		this.MP = new K.Ext.MainPanel({
			items : [ this.centerPanel, this.userResTree ]
		});
	},

	/**
	 * 创建左边资源树
	 */
	createUFGResTree : function() {
		var options = {
			title : "一级资源",
			iconCls : "p-panel",
			region : "west",
			width : "20%",
			margins : "2 2 2 2",
			rootVisible : false,
			root : {
				text : "root",
				children : ShortCutDI.getUserFirstGrideRes()
			}
		};
		var treePanel = new K.Ext.tree.TreePanel(options);
		return treePanel;
	},

	/**
	 * 中间面板
	 */
	createCenterPanel : function() {
		var me = this;
		var options = {
			region : "center",
			title : "设置快捷",
			margins : "2 2 2 0",
			iconCls : "p-edit",
			tbar : [ {
				text : "保存",
				iconCls : "save",
				handler : function() {
					var addIds = [], delIds = [];
					$("#shortCuts :checkbox").each(function(i, v) {
						if (this.checked) {
							addIds.push(this.value);
						} else {
							delIds.push(this.value);
						}
					});
					if (delIds.length != 0 || addIds.length != 0) {
						E.fireEvent("快捷-保存", addIds.join(","), delIds.join(","));
					} else {
						K.err("信息不全,无法设置快捷方式");
					}
				}
			} ]
		};
		return new K.Ext.Panel(options);
	}
});
